package cn.edu.jxust.controller.api.air;

import cn.edu.jxust.common.domain.web.api.air.IAirController;
import cn.edu.jxust.common.response.Result;
import cn.edu.jxust.common.response.ResultUtils;
import cn.edu.jxust.common.response.enums.ResultStatus;
import cn.edu.jxust.core.domain.repository.AirService;
import cn.edu.jxust.core.domain.repository.AqiService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;

/**
 * @author QiuKangming
 * @since 2020-06-29
 */
@Slf4j
@RestController
public class AirController implements IAirController {

    @Resource
    private AqiService aqiService;
    @Resource
    private AirService airService;

    @Override
    public Result getPollutionShareRate(Integer deviceId, String beginDate, String endDate){

        try{
            if (deviceId == null
                    || StringUtils.isEmpty(beginDate)
                    || StringUtils.isEmpty(endDate)) {
                return ResultUtils.resultWithoutData(ResultStatus.PARAM_ERROR, "请选择完整参数信息");
            }
            return aqiService.getPollutionShareRate(deviceId, beginDate, endDate);
        }catch (Exception e){
            log.error("AqiController --> getAqiList异常: {}", e.getMessage());
            return ResultUtils.resultWithoutData(ResultStatus.FAILED);
        }

    }

    @Override
    public Result getMainPollutionDays(Integer deviceId, String beginDate, String endDate){

        try{
            if (deviceId == null
                    || StringUtils.isEmpty(beginDate)
                    || StringUtils.isEmpty(endDate)) {
                return ResultUtils.resultWithoutData(ResultStatus.PARAM_ERROR, "请选择完整参数信息");
            }
            return aqiService.getMainPollutionDay(deviceId, beginDate, endDate);
        }catch (Exception e){
            log.error("AqiController --> getAqiList异常: {}", e.getMessage());
            return ResultUtils.resultWithoutData(ResultStatus.FAILED);
        }

    }

    @Override
    public Result getHasExceptionAir(Integer page, Integer size, Integer deviceId, Integer airType, String beginDate, String endDate){

        try{
            if (deviceId == null
                    || StringUtils.isEmpty(beginDate) || StringUtils.isEmpty(endDate)) {
                return ResultUtils.resultWithoutData(ResultStatus.PARAM_ERROR, "请选择完整信息");
            }
            return airService.getHasExceptionAir(page, size, deviceId, airType, beginDate, endDate);
        }catch (Exception e){
            log.error("AqiController --> getHasExceptionAir: {}", e.getMessage());
            return ResultUtils.resultWithoutData(ResultStatus.FAILED);
        }

    }

}

